package tpenchere.ui.menuBar;

import javax.swing.Box;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;

import tpenchere.controllers.ControllerInterface;
import tpenchere.model.User;

import org.jdesktop.application.ResourceMap;
import javax.swing.SwingConstants;
import java.awt.Component;
import javax.swing.JLabel;

public class LoggedMenuBar extends JMenuBar {
	private JMenu mnConnectedAs;
	ResourceMap resourceMap;
	
	public LoggedMenuBar(ResourceMap resourceMap, ControllerInterface controller) {
		this.resourceMap = resourceMap;
		
		JMenu mnFichier = new JMenu(resourceMap.getString("menuBar.connection.label"));
		this.add(mnFichier);
		
		JMenuItem mntmSenregistrer = new JMenuItem(controller.getActionMap().get("view.register"));
		
		mnFichier.add(mntmSenregistrer);
		
		JSeparator separator_1 = new JSeparator();
		mnFichier.add(separator_1);
		
		JMenuItem mntmChangeUser = new JMenuItem(controller.getActionMap().get("menuBar.logged.changeUser"));
		mnFichier.add(mntmChangeUser);
		
		JSeparator separator = new JSeparator();
		mnFichier.add(separator);
		
		JMenuItem mntmQuitter = new JMenuItem(controller.getActionMap().get("menuBar.connection.close"));
		mnFichier.add(mntmQuitter);
		
		JMenu mnAPropos = new JMenu(resourceMap.getString("menuBar.about.label"));
		this.add(mnAPropos);
		
		JMenuItem mntmProposDe = new JMenuItem(controller.getActionMap().get("menuBar.about.showAbout"));
		mnAPropos.add(mntmProposDe);
		
		this.add(Box.createHorizontalGlue());
		
		mnConnectedAs = new JMenu(resourceMap.getString("menuBar.logged.connectedAs.label"));
		this.add(mnConnectedAs);
		
		JMenuItem mntmUnlog = new JMenuItem(controller.getActionMap().get("menuBar.connection.unlog"));
		mnConnectedAs.add(mntmUnlog);		
	}
	
	public void setLoggedUser(User user) {
		mnConnectedAs.setText(resourceMap.getString("menuBar.logged.connectedAs.label") + user.pseudo);
	}

}
